using System;
using System.Data;

namespace CubeTimer.Storage
{
  public class CubeTimeRow
  {
    private readonly CubeTime m_cubeTime;

    public long ID
    {
      get
      {
        return m_cubeTime.Id;
      }
    }

    public DateTime WhenSolved
    {
      get
      {
        return m_cubeTime.When;
      }
    }

    public string Time
    {
      get
      {
        return TimeSpan.FromTicks(Ticks) == TimeSpan.MaxValue ? "DNF" : TimeSpan.FromTicks(Ticks).ToString();
      }
    }

    internal long Ticks
    {
      get
      {
        return m_cubeTime.ElapsedTicks;
      }
    }

    public string CubeType
    {
      get
      {
        return m_cubeTime.CubeType;
      }
    }

    public string Scramble
    {
      get
      {
        return m_cubeTime.Scramble;
      }
    }

    internal CubeTime CubeTime
    {
      get { return m_cubeTime; }
    }

    public CubeTimeRow(DataRow row)
    {
      m_cubeTime = new CubeTime((long)row[0], (DateTime)row[1], (long)row[2], row[3].ToString().Trim(), row[4].ToString().Trim());
    }

    public override string ToString()
    {
      return string.Format("{0} -> {1}", WhenSolved, Time);
    }
  }
}